package com.ruoyi.eval.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.validation.annotation.Validated;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.eval.domain.EvalPaper;
import com.ruoyi.eval.service.IEvalPaperService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 评价试卷Controller
 * 
 * @author yepanpan
 * @date 2025-05-06
 */
@RestController
@RequestMapping("/eval/paper")
public class EvalPaperController extends BaseController
{
    @Autowired
    private IEvalPaperService evalPaperService;

    /**
     * 查询评价试卷列表
     */
    @PreAuthorize("@ss.hasPermi('eval:paper:list')")
    @GetMapping("/list")
    public TableDataInfo list(EvalPaper evalPaper)
    {
        startPage();
        List<EvalPaper> list = evalPaperService.selectEvalPaperList(evalPaper);
        return getDataTable(list);
    }

    /**
     * 导出评价试卷列表
     */
    @PreAuthorize("@ss.hasPermi('eval:paper:export')")
    @Log(title = "评价试卷", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, EvalPaper evalPaper)
    {
        List<EvalPaper> list = evalPaperService.selectEvalPaperList(evalPaper);
        ExcelUtil<EvalPaper> util = new ExcelUtil<EvalPaper>(EvalPaper.class);
        util.exportExcel(response, list, "评价试卷数据");
    }


    /**
     * 获取评价试卷详细信息
     */
    @PreAuthorize("@ss.hasPermi('eval:paper:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(evalPaperService.selectEvalPaperById(id));
    }

    /**
     * 新增评价试卷
     */
    @PreAuthorize("@ss.hasPermi('eval:paper:add')")
    @Log(title = "评价试卷", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@Validated @RequestBody EvalPaper evalPaper)
    {
        evalPaper.setCreateBy(getUsername());
        return toAjax(evalPaperService.insertEvalPaper(evalPaper));
    }

    /**
     * 修改评价试卷
     */
    @PreAuthorize("@ss.hasPermi('eval:paper:edit')")
    @Log(title = "评价试卷", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@Validated @RequestBody EvalPaper evalPaper)
    {
                evalPaper.setUpdateBy(getUsername());
        return toAjax(evalPaperService.updateEvalPaper(evalPaper));
    }

    /**
     * 新增评价试卷
     */
    @PreAuthorize("@ss.hasPermi('eval:paper:add')")
    @Log(title = "评价试卷", businessType = BusinessType.INSERT)
    @PostMapping("copy")
    public AjaxResult copy(@Validated @RequestBody EvalPaper evalPaper)
    {
        evalPaper.setCreateBy(getUsername());
        return toAjax(evalPaperService.copyEvalPaper(evalPaper));
    }

    /**
     * 删除评价试卷
     */
    @PreAuthorize("@ss.hasPermi('eval:paper:remove')")
    @Log(title = "评价试卷", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(evalPaperService.deleteEvalPaperByIds(ids));
    }
}
